local chuanliu = fk.CreateSkill{
    name = "lingling__chuanliu"
}
Fk:loadTranslationTable{
    ["lingling__chuanliu"] = "湍流",
    [":lingling__chuanliu"] = "轮次技，当你需要使用基本牌时，你可以用中央区的所有牌交换手牌。若你因此失去并获得了需要使用的牌，你使用后重置此技能。",
    ["#lingling__chuanliu"] = "湍流：你可以用中央区的所有牌交换手牌",
    ["#lingling__chuanliu-use"] = "湍流：你可以使用一张【%arg】并重置此技能",
}

chuanliu:addEffect("viewas", {
    prompt = "#lingling__chuanliu",
    pattern = ".|.|.|.|.|basic",
    interaction = function (self, player)
        local all_names = Fk:getAllCardNames("b")
        local names = player:getViewAsCardNames(chuanliu.name, all_names)
        if #names == 0 then return end
        return UI.CardNameBox {choices = names, all_names = all_names}
    end,
    card_filter = Util.FalseFunc,
    view_as = function (self, player, cards)
        if not self.interaction.data or (#player:getCardIds("h") == 0 and #Fk:currentRoom():getBanner("@$CenterArea") == 0) then return end
        local card = Fk:cloneCard(self.interaction.data)
        card.skillName = chuanliu.name
        return card
    end,
    before_use = function (self, player, use)
        local room = player.room
        local trueName = use.card.trueName
        local cards1, cards2 = player:getCardIds("h"), room:getBanner("@$CenterArea")
        room:swapCardsWithPile(player, cards1, cards2, chuanliu.name, "discardPile", true, player)
        if table.find(cards1, function (cardID)
            return Fk:getCardById(cardID).trueName == trueName
        end) and table.find(cards2, function (cardID)
            return Fk:getCardById(cardID).trueName == trueName
        end) then
            local ids = table.filter(player:getCardIds("h"), function (cardID)
                return Fk:getCardById(cardID).trueName == trueName
            end)
            local card = room:askToCards(player, {
                max_num = 1,
                min_num = 1,
                pattern = tostring(Exppattern{id = ids}),
                skill_name = chuanliu.name,
                cancelable = true,
                prompt = "#lingling__chuanliu-use:::"..trueName
            })
            if #card > 0 then
                use.card:addSubcards(card)
                player:setSkillUseHistory(chuanliu.name, 0, Player.HistoryGame)
            else
                return chuanliu.name
            end
        end
    end,
    enabled_at_play = function(self, player)
        local all_names = Fk:getAllCardNames("b")
        local names = player:getViewAsCardNames(chuanliu.name, all_names)
        return #names > 0 and player:usedSkillTimes(chuanliu.name, Player.HistoryRound) == 0
    end,
    enabled_at_response = function(self, player, response)
        local all_names = Fk:getAllCardNames("b")
        local names = player:getViewAsCardNames(chuanliu.name, all_names)
        return not response and #names > 0 and player:usedSkillTimes(chuanliu.name, Player.HistoryRound) == 0
    end,
})

chuanliu:addAcquireEffect(function (self, player, is_start)
    player.room:addSkill("#CenterArea")
end)

return chuanliu